package com.xk.sport.backend.service;

import com.xk.sport.backend.dao.repository.CommunityDao;
import com.xk.sport.backend.dao.model.Community;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommunityService {
    @Autowired
    private CommunityDao communityDao;

    public List<Community> findAll() {
        return communityDao.findAll();
    }

    public List<Community> findAllByAreaId(long areaId) {
        return communityDao.findByAreaId(areaId);
    }

    public Community findOne(long id) {
        return communityDao.findOne(id);
    }

    public Community add(Community community) {
        if (community == null || community.getId() > 0) {
            return null;
        }
        community.setCreateTime(System.currentTimeMillis());
        return communityDao.save(community);
    }

    public Community update(Community community) {
        if (community == null || community.getId() <= 0) {
            return null;
        }
        return communityDao.save(community);
    }

    public boolean delete(long id) {
        communityDao.delete(id);
        return true;
    }
}
